package com.customization.unionpay.market.dao;

import com.alibaba.fastjson.JSONObject;
import com.customization.unionpay.market.util.FormUtil;
import weaver.backup.logging.Logger;
import weaver.backup.logging.LoggerFactory;
import weaver.conn.RecordSet;

import java.util.List;

public class FinancialMattersDao {
    public Logger log = LoggerFactory.getLogger(FinancialMattersDao.class);

    public boolean insert(List<JSONObject> jsonObjects) {
        // 构建 SQL 插入语句
        StringBuilder sql = new StringBuilder();
        sql.append("INSERT INTO ").append(FormUtil.FINANCIAL_MATTERS).append(" (")
                .append("jbr,yxpthdsqm,,bdh,cwsfjs").append(") VALUES ");

        boolean isFirst = true;
        for (JSONObject jsonObject : jsonObjects) {
            if (!isFirst) {
                sql.append(", ");
            } else {
                isFirst = false;
            }
            sql.append("(")
                    .append("'").append(jsonObject.getString("sqr")).append("', ") // jbr 字段
                    .append("'").append(jsonObject.getString("yxpthdsqm")).append("', ") // yxpthdsqm 字段
                    .append("'").append(jsonObject.getString("bdh")).append("', ") // bdh 字段
                    .append("'是'"); // cwsfjs 字段永远为 '是'
            sql.append(")");
        }
        RecordSet rs = new RecordSet();
        boolean result = rs.execute(sql.toString());
        if (!result) {
            log.error("财务事项结束数据插入失败");
        }
        return result;
    }
}
